<%@page import="com.surelution.projects.crm.NoGasTypeCategory"%>
<%@page import="com.surelution.projects.crm.GasType"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="main"/>
<g:set var="entityName" value="${message(code: 'gasList.label', default: 'gasList')}" />
<g:javascript library="jquery"/>
<link rel="stylesheet" href="${resource(dir:'css',file:'defaultTheme.css')}" />
<script type="text/javascript" src="${resource(dir:'js/jquery',file:'jquery.fixedheadertable.min.js')}"></script>
<script type="text/javascript" src="${resource(dir:'js/jquery',file:'jquery.printElement.min.js')}"></script>
<title><g:message code="default.monthreport.label" args="[entityName]" /></title>
	<script type="text/javascript">
		$(document).ready(function() {
		   $("#simplePrint").click(function() {
		       printElem({leaveOpen: true, printMode: 'popup', overrideElementCSS: ["${resource(dir:'plugins/richui-0.8/css',file:'calendarmonthview.css')}","${resource(dir:'css',file:'main.css')}"]});
		   });
		   $('#myTable01').fixedHeaderTable({ footer: false, cloneHeadToFoot: false, autoShow: true });
		});
		function printElem(options){
		    $('#report').printElement(options);
		};
		
	</script>
	<script type="text/javascript" src="${resource(dir:'js/datechooser',file:'datechooser.js')}"></script>
</head>

<body>
  <div class="body">
          <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
          </div>
          <div>
            <p style="font-size:16px;color:#000;margin:10px 0;">加油站月报</p>
        	<g:form >
        		选择日期:<g:datePicker name="month" precision="month" value="${month }"/>
			    <span class="menuButton" style="margin-right:5px;"><g:actionSubmit value="${message(code: 'default.button.search.label', default: 'report')}" action="monthReport"/></span>
    			<span class="menuButton"><g:actionSubmit value="${message(code: 'default.button.export.label', default: 'Export')}" action="monthExportReport"/></span>
			    <input type="button" value="打印报表" id="simplePrint" /><br>
    			选择片区：    				
    			<g:each in="${com.surelution.projects.crm.StationArea.list()}" var="area">
	    			<g:checkBox id="stationArea.id_${area.id }" name="stationArea" value="${area.id }" checked="${stationArea!=[]?stationArea.contains(area.id):true}"/><label for="stationArea.id_${area.id }">${area.areaName}</label>&nbsp;
    			</g:each>			
			</g:form>
			<g:if test="${flash.message}">
            	<div class="message">${flash.message}</div>
            </g:if>
        </div>
        <%
			def tgasSale=0,tfuelSale=0,tAllSale=0,tnoGasAll=0,tnoGasMaoLi=0,tcardSale=0
		 %>
        <div id="report" style="height:650px;">
	    	<label style="font-size:16px;color:#0f3072;">油品销量计划完成量  ${startDay.format("yyyy年MM月dd日")}到${endDay.format("yyyy年MM月dd日")}</label>
        		<table id="myTable01">
	        		<thead>
        			<tr>
	        			<td colspan="3"></td>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;" colspan="5">油品</td>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;" colspan="4">非油品</td>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;" colspan="4">加油卡</td>
        			</tr>
	        		<tr>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">序号</td>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">片区</td>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">加油站名</td>
        				<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">汽油(吨)</td>
        				<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">柴油(吨)</td>
        				<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">合计(吨)</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">月度完成率</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">年度完成率</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">销售收入</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">毛利</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">月度完成率</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">年度完成率</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">发卡量</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">月度完成率</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">月度卡销比</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">年度完成率</td>
	    			</tr>
	    			<tr class="even" style="width:870px;overflow:auto;">
						<td style="text-align:center;">合计</td>
    					<td style="text-align:center;width:50px;"></td>
    					<td style="text-align:center;width:100px;"></td>
						<td style="text-align:center;"><div id="tgasSale"></div></td>
						<td style="text-align:center;"><div id="tfuelSale"></div></td>
						<td style="text-align:center;"><div id="tAllSale"></div></td>
						<td style="text-align:center;">${gasMonthFinish}%</td>
						<td style="text-align:center;">${gasYearFinish}%</td>
						<td style="text-align:center;"><div id="tnoGasAll"></div></td>
						<td style="text-align:center;"><div id="tnoGasMaoLi"></div></td>
						<td style="text-align:center;">${noGasMonthFinish }%</td>
						<td style="text-align:center;">${noGasYearFinish }%</td>
						<td style="text-align:center;"><div id="tcardSale"></div></td>
						<td style="text-align:center;">0</td>
						<td style="text-align:center;">0</td>
						<td style="text-align:center;">0</td>
    				</tr>
    				</thead>
    				<tbody>
    				<g:each in="${mapList}" var="r" status="i">
    				<%
						tgasSale += r.get("gasSale")
					   	tfuelSale += r.get("fuelSale")
					   	tAllSale += r.get("AllSale")
					   	tnoGasAll += r.get("noGasAll")
					   	tnoGasMaoLi += r.get("noGasMaoLi")
						tcardSale += r.get("cardSale")
				 	%>
					<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
    					<td style="text-align:center;">${i+1}</td>
	    				<td style="text-align:center;">${r.get("area")}</td>
	    				<td style="text-align:center;"> ${r.get("station").shortName}</td>
						<td style="text-align:center;">${r.get("gasSale")}</td>
						<td style="text-align:center;">${r.get("fuelSale")}</td>
						<td style="text-align:center;">${r.get("AllSale")}</td>
						<td style="text-align:center;">${r.get("monthFinish")}%</td>
						<td style="text-align:center;">${r.get("yearFinish")}%</td>
						<td style="text-align:center;">${r.get("noGasAll")}</td>
						<td style="text-align:center;">${r.get("noGasMaoLi")}</td>
						<td style="text-align:center;">${r.get("noGasMonthFinish")}%</td>
						<td style="text-align:center;">${r.get("noGasYearFinish")}%</td>
						<td style="text-align:center;">${r.get("cardSale")}</td>
						<td style="text-align:center;">${r.get("cardMonthFinish")}%</td>
						<td style="text-align:center;">${r.get("cardProp")}%</td>
						<td style="text-align:center;">${r.get("cardYearFinish")}%</td>
    				</tr>
    				</g:each>
    				</tbody>
          	</table>
        </div>
 		<script type="text/javascript">
			document.getElementById("tgasSale").innerHTML = '${(formatNumber(number:tgasSale,maxFractionDigits:3)) }';
			document.getElementById("tfuelSale").innerHTML = '${(formatNumber(number:tfuelSale,maxFractionDigits:3)) }';
			document.getElementById("tAllSale").innerHTML = '${(formatNumber(number:tAllSale,maxFractionDigits:3)) }';
			document.getElementById("tnoGasAll").innerHTML = '${(formatNumber(number:tnoGasAll,maxFractionDigits:2)) }';
			document.getElementById("tnoGasMaoLi").innerHTML = '${(formatNumber(number:tnoGasMaoLi,maxFractionDigits:2)) }';
			document.getElementById("tcardSale").innerHTML = '${tcardSale}';
        </script>
    	<g:if test="${mapList==[]}">
           	<div class="message">${message(code: 'default.nofound.message')}</div>
    	</g:if>
    	

  </div>
</body>
</html>